Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update middleware.mdx #10810

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Update middleware.mdx #10810

wants to merge 2 commits into from

Conversation

ruohki
Copy link

@ruohki ruohki commented Jan 26, 2025

Description (required)

Updated the env.d.ts section to reflect the current working implementation

  • Suggested label: code snippet update

discord: ruohki

Updated the env.d.ts section to reflect the current working implementation
Copy link

netlify bot commented Jan 26, 2025

Deploy Preview for astro-docs-2 ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit 82a95f5
🔍 Latest deploy log https://app.netlify.com/sites/astro-docs-2/deploys/6796b800040dad0008a9a60a
😎 Deploy Preview https://deploy-preview-10810--astro-docs-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@astrobot-houston
Copy link
Contributor

astrobot-houston commented Jan 26, 2025

Lunaria Status Overview

🌕 This pull request will trigger status changes.

Learn more

By default, every PR changing files present in the Lunaria configuration's files property will be considered and trigger status changes accordingly.

You can change this by adding one of the keywords present in the ignoreKeywords property in your Lunaria configuration file in the PR's title (ignoring all files) or by including a tracker directive in the merged commit's description.

Tracked Files

File Note
en/guides/middleware.mdx Source changed, localizations will be marked as outdated.
Warnings reference
Icon Description
🔄️ The source for this localization has been updated since the creation of this pull request, make sure all changes in the source have been applied.

@astrobot-houston
Copy link
Contributor

Hello! Thank you for opening your first PR to Astro’s Docs! 🎉

Here’s what will happen next:

  1. Our GitHub bots will run to check your changes.
    If they spot any broken links you will see some error messages on this PR.
    Don’t hesitate to ask any questions if you’re not sure what these mean!

  2. In a few minutes, you’ll be able to see a preview of your changes on Netlify 🥳.

  3. One or more of our maintainers will take a look and may ask you to make changes.
    We try to be responsive, but don’t worry if this takes a few days.

Comment on lines 144 to 154
declare global {
namespace App {
interface Locals {
user: {
name: string
},
welcomeTitle: () => string,
orders: Map<string, object>
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ruohki and thanks for taking the time to help making the docs better!

I don't know if you followed the discussion in Discord but I don't think we should use declare global here because without imports it is working as expected. But I agree, we should show how to use an imported type as it seems to be confusing. Perhaps something like:

Suggested change
declare global {
namespace App {
interface Locals {
user: {
name: string
},
welcomeTitle: () => string,
orders: Map<string, object>
}
}
}
namespace App {
interface Locals {
site: {
title: string
},
welcomeTitle: () => string,
orders: Map<string, object>,
user: import("@supabase/supabase-js").User
}
}

Copy link
Author

@ruohki ruohki Jan 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm so maybe we could show both versions and mention that if someone is using imports to use the global approach? Or yeah at least clarify on how to use imported types. I do this regularly, sort of misuse locals as my little singleton accesor
Edit: made change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, that looks better since I think the example should remain an ambient module declaration!

Regarding the format (as a commented property or not, or if we need to mention that it is Typescript behavior), I'm not sure what is best so I'll let Sarah (or someone else) give their opinion since it's kind of new content. She'll probably be able to give better advice! 😄 I will post a comment with a bit more context for reviewers.

@ArmandPhilippot
Copy link
Member

PR's context:
This issue has already been discussed earlier on Discord and Fryuni already gives great explanations regarding the use of imports in .d.ts files. It's a Typescript behavior but it seems to confuse some users.

This issue was raised again yesterday, so (after ruohki's PR) the idea was to provide an example on how to do imports in a .d.ts to avoid turning it into a normal module and using declare global.

I think adding a property could be enough to show that, but is it clear enough? I know we avoid documenting the behavior of third-party technologies, but should we add more context here?

@sarah11918
Copy link
Member

A comment from maintainer's discussion:

Actual docs rather than a comment might be better? Plus also maybe an example with an Astro type rather than an external dependency?

@sarah11918 sarah11918 added the improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes) label Jan 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve or update documentation Enhance / update existing documentation (e.g. add example, improve description, update for changes)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants